﻿import 'package:get/get.dart';
import 'package:getx_scaffold/common/utils/toast_util.dart';
import 'package:azring/core/repository/default_api.dart';
import '../routes.dart';

class FeedbackHistoryLogic extends GetxController {
  final feedbackList = <Map<String, dynamic>>[].obs;
  final isLoading = false.obs;

  @override
  void onInit() {
    super.onInit();
    loadFeedbackList();
  }

  /// 加载反馈列表
  Future<void> loadFeedbackList() async {
    isLoading.value = true;
    try {
      final result =
          await DefaultApi().queryFeedbackListGet<Map<String, dynamic>>();

      if (result != null && result['data'] != null) {
        feedbackList.value = List<Map<String, dynamic>>.from(result['data']);
      } else {
        feedbackList.clear();
      }
    } catch (e) {
      Toast.show('加载失败：${e.toString()}');
    } finally {
      isLoading.value = false;
    }
  }

  /// 跳转到反馈详情
  void goToFeedbackDetail(String id) {
    Get.toNamed(SettingsRoutes.feedbackDetail, arguments: {'id': id});
  }
}
